/*
 * @Author: 码上talk|RC
 * @Date: 2021-08-09 16:54:12
 * @LastEditTime: 2022-01-03 10:16:30
 * @LastEditors: 码上talk|RC
 * @Description: 
 * @FilePath: /ma-portal/model/entity/member/index.js
 * @微信:  13680065830
 * @邮箱:  3189482282@qq.com
 * @oops: Just do what I think it is right
 */
/*
 * @Author: 码上talk|RC
 * @Date: 2020-12-29 17:53:17
 * @LastEditTime: 2021-08-03 11:31:30
 * @LastEditors: 码上talk|RC
 * @Description:
 * @FilePath: /web-shop/src/renderer/modelV2/entity/member/index.js
 * @微信:  13680065830
 * @邮箱:  3189482282@qq.com
 * @oops: Just do what I think it is right
 */

import Entity from '../../entity.class.js';
import options from '../../json/options/member';

const _tableField = {
    distributorPId: {
        type: 'int',
        default: 0
    },
    type: {
        type: 'int',
        default: 0
    },
    levelId: {
        type: 'int',
        default: 0
    },
    username: {
        type: 'string',
        default: ''
    },
    nickname: {
        type: 'string',
        default: ''
    },
    mobile: {
        type: 'string',
        default: ''
    },
    fullAddress: {
        type: 'string',
        default: ''
    },
    inviteCode: {
        type: 'string',
        default: ''
    },
    inviteCodeWxEntry: {
        type: 'string',
        default: ''
    },
    memberAccount: {
        type: 'Object',
        default: {}
    },
    memberShopAccount: {
        type: 'Object',
        default: {}
    },
    memberStatistics: {
        type: 'Object',
        default: {}
    },
    memberAchieve: {
        type: 'Object',
        default: {}
    },
    distributor: {
        type: 'Object',
        default: {}
    },
    parent: {
        type: 'Object',
        default: {}
    },
    achieveQueryIsEnable: {
        type: 'int',
        default: 0
    }
};

class Member extends Entity {
    static _requestConfig = {
        app: 'portal',
        domain: 'member'
    }

    static _form = {}

    static options = options

    get typeStr () {
        return _.get(_.find(options['type'], x => { return x.value === this.type }), 'label');
    }

    get levelStr () {
        return _.get(_.find(options['level'], x => { return x.value === this.levelId }), 'label');
    }

    get rewardInfo () {
        let unGive = 0;
        let give = 0;
        unGive = _.get(this, 'memberStatistics.rewardDistributor', 0) + _.get(this, 'memberStatistics.rewardPromoteGold', 0) + _.get(this, 'memberStatistics.rewardPromoteSilver', 0) + _.get(this, 'memberStatistics.rewardVip', 0) + _.get(this, 'memberStatistics.rewardPromoteVip', 0);
        give = _.get(this, 'memberStatistics.addUpReward', 0) - unGive;
        return {
            unGive,
            give
        }
    }

    constructor (member) {
        super(member, { _tableField });
    }
}

export default Member;
